{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "f5c09a32-89c3-482b-bfe3-fb26432bc7f3",
   "metadata": {},
   "outputs": [],
   "source": [
    "def f(x): \n",
    "    return x * x; \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "85a8d201-162e-473e-875d-3ce716b5e655",
   "metadata": {},
   "outputs": [],
   "source": [
    "r= map(f, [1,2,3,4,5,6])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "34a8e47b-3fe7-4d4b-adf0-d4bb1e9c4bee",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 4, 9, 16, 25, 36]"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list(r)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "ba2ca48e-74dc-4cf0-b2e6-4ca2bd3a1fc4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['1', '2', '3', '4', '5', '6', '7', '8', '9']"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list(map(str, [1,2,3,4,5,6,7,8,9]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "b0eb858f-f86e-4a0f-b46b-8cf0165d7d81",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "25"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from functools import reduce\n",
    "def add(x, y):\n",
    "    return x + y\n",
    "\n",
    "reduce(add, [1, 3, 5, 7, 9])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "c1095154-34dc-4ba9-bc22-981eefbedd43",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "124"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "def fn(x, y):\n",
    "    return x* 10 + y \n",
    "def char2num(s): \n",
    "    digits = {'0': 0, '1': 1, '2': 2, '3': 3, '4': 4}\n",
    "    return digits[s]\n",
    "reduce(fn, map(char2num, '124'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "95e92be1-954b-4a62-a4d9-4c0118da7ea3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 2, 4]"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list(map(char2num, '124'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "dea55f07-73c4-4d10-9ad2-1f77cb4e7789",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "a\n",
      "b\n",
      "c\n"
     ]
    }
   ],
   "source": [
    "def normalize(name):\n",
    "    for x in name: \n",
    "        print(x)\n",
    "normalize('abc')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "bf5329d6-4838-4ed6-88c9-50d2762f4b3a",
   "metadata": {},
   "outputs": [],
   "source": [
    "def prod(L): \n",
    "    def multi(x, y): \n",
    "        return x * y\n",
    "    return reduce(multi, L)\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "3d53d612-3202-4707-9ca9-86507c7ae74a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "945"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "prod([3,5,7,9])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "323cd699-9b8b-4175-ac3d-7e87f527e170",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.21"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
